import { Graph, Addon, Shape } from "@antv/x6";
import Bus from "@/utils/bus.js";
import { deepMerge } from "@/utils/tool.js";
import { getuuid } from "@/utils/index.js";
let defaultConfig = {
  background: {
    color: "rgb(0 0 0)",
  },
  snapline: true, // 对齐线
  scroller: {
    enabled: false,
    pannable: true,
    pageVisible: true,
    pageBreak: false,
  },
  mousewheel: {
    enabled: true,
    modifiers: ["ctrl", "meta"],
  },
  panning: {
    enabled: true,
    modifiers: "ctrl",
    cursor: "default",
  }, // 支持拖拽
  selecting: true,
  interacting: function (cellView) {
    if (cellView.cell.data && cellView.cell.data.type === "text") return false;
    return true;
  },
  grid: {
    // 网格线
    size: 10,
    visible: false,
    type: "doubleMesh",
    args: [
      {
        color: "#eee", // 主网格线颜色
        thickness: 1, // 主网格线宽度
      },
      {
        color: "#ddd", // 次网格线颜色
        thickness: 1, // 次网格线宽度
        factor: 4, // 主次网格线间隔
      },
    ],
  },
};
export const initGraph = function initGraph(container, config) {

  config ? config : (config = {});
  defaultConfig = deepMerge(defaultConfig, config);

  window.$graph = new Graph({
    container: container,
    ...defaultConfig,
  });
};


export const createBasicPointNode = function createBasicPointNode(obj) {
  let point = obj.point;
  return window.$graph.createNode({
    shape: point.shape,
    width: point.width,
    height: point.height,
    zIndex: point.zIndex,
    attrs: {
      body: {
        fill: point.fill,
        stroke: point.stroke,
        strokeWidth: point.strokeWidth
      }
    },
    data: {}
  })
}